package server;

import common.Level;
import common.Player;
import common.GameState;

public class UpdateableGameImpl implements UpdateableGame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4043411675615330860L;
	
	private String message;
	private GameState state;
	private UpdateablePlayer[] player;
	private Boolean[][] coin;
	private int colorChangeCount = 0;
	private int coinsLeft;
	
	public UpdateableGameImpl() {
		state = GameState.WaitingForPlayers;
	}
		
	@Override
	public GameState getPlayingState() {
		return state;
	}

	@Override
	public Player[] getPlayer() {
		return player;
	}
	
	public UpdateablePlayer[] getUpdateablePlayer() {
		return player;
	}

	@Override
	public boolean hasMessage() {
		return message != null;
	}

	@Override
	public String getMessage() {
		return message;
	}

	@Override
	public void setPlayer(UpdateablePlayer[] p) {
		player = p;
	}

	@Override
	public void setPlayingState(GameState s) {
		state = s;
	}

	@Override
	public void setMessage(String m) {
		message = m;
	}

	@Override
	public void removeCoin(int i, int j) {
		coin[i][j] = false;
		coinsLeft--;
	}

	public int getCoinsLeft(){
		return coinsLeft;
	}
	
	@Override
	public Boolean coinOnField(int i, int j) {
		return coin[i][j];
	}

	@Override
	public Boolean[][] getCoins() {
		return coin;
	}

	public void setCoins(Boolean[][] coin) {
		this.coin = coin;
	}
	
	public void increaseColorChangeCount(){
		this.colorChangeCount++;
	}
	
	public void resetColorChangeCount(){
		this.colorChangeCount = 0;
	}
	
	public int getColorChangeCount(){
		return colorChangeCount;
	}

	@Override
	public void resetCoins( Level level) {
		if( coin == null)
			coin = new Boolean[level.getRowAmount()][level.getColumnAmount()];
		for( int i = 0; i < coin.length; i++)
			for( int j = 0; j < coin[0].length; j++)
				coin[i][j] = true;
		coinsLeft = level.getRowAmount()*level.getColumnAmount();
	}
}
